﻿using System.Collections;
using System.Data.Entity;
using System.Web.Configuration;
using Elmah;

namespace Rickie.IsCoding.DemoSite.Models {
	/// <summary>
	///     Utility class
	/// </summary>
	public static class Utils {
		/// <summary>
		///     Dynamically get connection string name based on execution environment:
		/// </summary>
		/// <returns>
		///     DefaultConnection if we are in debug mode, AzureDBConnection otherwise.
		/// </returns>
		public static string GetConnectionStringName() {
#if DEBUG
			return "DefaultConnection";
#else
			return "AzureDBConnection";
#endif
		}
	}

	/// <summary>
	/// Smart Log
	/// </summary>
	public class SmartErrorLog : SqlErrorLog
	{
		public SmartErrorLog(IDictionary config) : base(config) {}

		public SmartErrorLog(string connectionString) : base(connectionString) {}

		public override string ConnectionString
		{
			get { return WebConfigurationManager.ConnectionStrings[Utils.GetConnectionStringName()].ConnectionString; }
		}
	}
}